<?php

if (!class_exists('objectPage')) {
    require(CORE_INCLUDE_DIR.'/objectPage.php');
}
class admin_track extends objectPage{
    var $object = 'plugins/express_manager/track';
    var $finder_default_cols = 'express_id';
    var $workground = 'order';
    //var $filterUnable = true;
    
    function admin_track(){
        
        parent::objectPage();
        $this->view_dir = dirname(__FILE__).'/view/admin';
        $this->finder_action_tpl = $this->view_dir.'/track/finder_action.html';
        //$this->finder_filter_tpl=$this->view_dir.'/track/finder_filter.html';
    }
    function export(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::export();
    }
    function colsetting(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::colsetting();
    }
    function detail($object_id,$func=null){
          $this->template_dir = CORE_DIR.'/admin/view/';
          parent::detail($object_id,$func=null);
    }
    function index(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::index();
    }

    function addNew(){
        $this->path[] = array('text'=>__('添加快件跟踪信息'));
        $timeHours = array();
        for($i=0;$i<24;$i++){
            $v = ($i<10)?'0'.$i:$i;
            $timeHours[$v] = $v;
        }
        $timeMins = array();
        for($i=0;$i<60;$i++){
            $v = ($i<10)?'0'.$i:$i;
            $timeMins[$v] = $v;
        }
        $this->pagedata['timeHours'] = $timeHours;
        $this->pagedata['timeMins'] = $timeMins;
        $this->pagedata['timeSecs'] = $timeMins;
        $this->pagedata['status'] = array (
            'progress' => __('运送中'),
            'succ' => __('已签收'),
            'failed' => __('发货失败'),
            'cancel' => __('已取消'),
            'lost' => __('货物丢失'),
            'timeout' => __('超时'),
            //'ready' => __('准备发货'),
        );
        $this->pagedata['filter'] = '';
        $this->display('view/admin/track/addNew.html');
    }

    function edit($id)
    {
        $objTrack = &$this->system->loadModel($this->object);
        $row = $objTrack->getFieldById($id);
        $timeHours = array();
        for($i=0;$i<24;$i++){
            $v = ($i<10)?'0'.$i:$i;
            $timeHours[$v] = $v;
        }
        $timeMins = array();
        for($i=0;$i<60;$i++){
            $v = ($i<10)?'0'.$i:$i;
            $timeMins[$v] = $v;
        }
        $this->pagedata['timeHours'] = $timeHours;
        $this->pagedata['timeMins'] = $timeMins;
        $this->pagedata['timeSecs'] = $timeMins;
        $this->pagedata['sel_hour'] = date('H',$row['op_time']);
        $this->pagedata['sel_min'] = date('i',$row['op_time']);
        $this->pagedata['sel_sec'] = date('s',$row['op_time']);
        $this->pagedata['status'] = array('active'=>'运输中','finish'=>'已完成',);
        $this->pagedata['data'] = $row;
        $this->display('view/admin/track/edit.html');
    }

    function save()
    {
        $this->template_dir = CORE_DIR.'/admin/view/';
        $this->begin('index.php?ctl=plugins/track&act=index');
        if (!$express_id = trim($_POST['express_id'])) {
            $this->end(false,'快件单号不能为空');
        }
        $data = $_POST;
        $data['express_id'] = $express_id;
        $post_time = $_POST['operate_time'];
        $optime = date('Y-m-d',$_POST['operate_date']).' '.$post_time['hour'].':'.$post_time['min'].':'.$post_time['sec'];
        $data['op_time'] = strtotime($optime);
        $data['uptime'] = time();
        if (!$data['id']) {
            $data['createtime'] = $data['uptime'];
        }
        $data['op_user'] = $this->system->op_id;
        $objTrack = &$this->system->loadModel($this->object);
        if (!$result = $objTrack->save($data)) {
            $this->end(false,__('保存失败'));
        } else {
            $this->end(true,__('保存成功'));
        }
    }
}

?>
